package client

import (
	"context"
	"log"
	"smallnest-rpcx/services"

	"github.com/smallnest/rpcx/client"
)

//异步客户端
func StartAsyncClient() {
	_client := client.NewClient(client.DefaultOption)

	err := _client.Connect("tcp", "127.0.0.1:8972")
	if err != nil {
		log.Fatalf("failed to connect: %v", err)
	}
	defer _client.Close()

	args := &services.Args{
		A: 10,
		B: 20,
	}

	reply := &services.Reply{}
	call := _client.Go(context.Background(), "Arith", "Mul", args, reply, nil)
	if err != nil {
		log.Fatalf("failed to call: %v", err)
	}

	repled := <-call.Done
	if repled.Error != nil {
		log.Fatalf("failed to call: %v", repled.Error)
	}
	log.Println(reply.C)

}
